package HuaWeiOd.AA;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class 查找重复代码 {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
 
        String a = in.nextLine();
        String b = in.nextLine();
 
        String x = a.length() < b.length() ? a : b;
        String y = a.length() > b.length() ? a : b;
        
        int yl =0, yr = 1;
        String res = "";
        while (yl < yr && yr < y.length()) {
            String ys = y.substring(yl, yr);
            boolean flag = false;
            while (yr < y.length() && x.contains(ys)) {
                yr++;
                ys = y.substring(yl, yr);
                flag = true;
            }
            if (flag) {
                res = res.length() < y.substring(yl, yr - 1).length() ? y.substring(yl, yr - 1) : res;
            } else {
                yl++;
                yr = yl+1;
            }
        }
        System.out.println(res);
    }
}
/*
private_void_metho1
public_void_method

hello123world
hello123abc4

hiworld
hiweb

ahiworld
bhiweb
 */